{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9ddd1917",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表的其他方法（Sequnce Types 的一些方法）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c09bfed3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name的长度/names的列表元素个数：  4\n"
     ]
    }
   ],
   "source": [
    "# 1.len()查看list长度\n",
    "names = [\"mike\", \"mary\", \"jan\", \"jack\"]\n",
    "print(\"name的长度/names的列表元素个数： \", len(names) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f089b1bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "# 2. in 查看元素是否存在list当中,结果为布尔值，False/True,\n",
    "#   一般在操作list的修改和删除时会先判断\n",
    "names = [\"mike\", \"mary\", \"jan\", \"jack\"]\n",
    "print(\"junk\" in names)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d8a413b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['mike', 'mary', 'jan', 'jack', 'junk']\n"
     ]
    }
   ],
   "source": [
    "#  列表的私有方法\n",
    "names = [\"mike\", \"mary\", \"jan\", \"jack\"]\n",
    "# 增加的方法\n",
    "# 1. .append(增加)\n",
    "names.append(\"junk\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3f23e4fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['chao', 'mike', 'mary', 'chao', 'jan', 'jack', 'junk']\n"
     ]
    }
   ],
   "source": [
    "# 2. .insert(在某个地方增加)\n",
    "names.insert(2, \"chao\")\n",
    "# 列表里面可以放入重复的值\n",
    "names.insert(0, \"chao\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "326b9119",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "['mike', 'mary', 'jan', 'jack']\n"
     ]
    }
   ],
   "source": [
    "# 删减的方法\n",
    "names = [\"mike\", \"mary\", \"jan\", \"jack\"]\n",
    "# 1. 一般情况下 使用remove先用in做判断\n",
    "\n",
    "#  in 判断内容在不在某段里面\n",
    "print(\"chao\" in names)\n",
    "#  .remove删除列表某一值\n",
    "# names.remove(\"chao\")\n",
    "\n",
    "#  remove 完整版\n",
    "print(\"junk\" in names)\n",
    "if \"junk\" in names:\n",
    "    names.remove(\"junk\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cb90ce7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pop()方法后的names ['chao', 'mary', 'chao', 'jan', 'jack', 'junk']\n"
     ]
    }
   ],
   "source": [
    "# 2. .pop 删除位置为x的这个元素\n",
    "names = ['chao', 'mike', 'mary', 'chao', 'jan', 'jack', 'junk']\n",
    "names.pop(1)\n",
    "print(\"pop()方法后的names\", names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8c00d1a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "# 3. .index()索引 查看该元素如10001 在stu_id中第一个出现的位置索引\n",
    "stu_id = [1001, 2002, 3003, 4004, 5005, 1001, 6006, 7007, 8008, 9009, 1001]\n",
    "print(stu_id.index(1001))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f2f556df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "清除names列表后的值： None\n"
     ]
    }
   ],
   "source": [
    "# 4. .clear()清除所有数据\n",
    "names = ['chao', 'mike', 'mary', 'chao', 'jan', 'jack', 'junk']\n",
    "print(\"清除names列表后的值：\",names.clear())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "3b40d5dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "清除names列表后的值： []\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "names = ['chao', 'mike', 'mary', 'chao', 'jan', 'jack', 'junk']\n",
    "names.clear()\n",
    "print(\"清除names列表后的值：\",names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ff77164f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "count方法的结果: 3\n",
      "[1001, 2002, 3003, 4004, 5005, 1001, 6006, 7007, 8008, 9009, 1001]\n"
     ]
    }
   ],
   "source": [
    "# 5. .count()查看列表元素出现的个数，（简单应用）统计分数出现的次数\n",
    "stu_id = [1001, 2002, 3003, 4004, 5005, 1001, 6006, 7007, 8008, 9009, 1001]\n",
    "print(\"count方法的结果:\",stu_id.count(1001))\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f92241c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1001, 2002, 3003, 4004, 5005, 1001, 6006, 7007, 8008, 9009, 1001]\n"
     ]
    }
   ],
   "source": [
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "20585ddc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1001, 2002, 3003, 4004, 5005, 1001, 6006, 7007, 8008, 9009, 1001]\n"
     ]
    }
   ],
   "source": [
    "# 6. .extend() 是给指定的list进行扩充\n",
    "names.extend(stu_id)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3dc9369",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
